import axios from "axios";
import Cookies from 'js-cookie'
// 请求拦截器
axios.interceptors.request.use(function (config) {
    // 给请求头设置token
    // let token = localStorage.getItem('token')
    // if(token){
    //     config.headers['X-Nideshop-Token'] = token 
    // }
      const jwt = Cookies.get('jwt')
      if(jwt){
        config.headers['Authorization'] = jwt
      }
    return config;
  }, function (error) {
    // Do something with request error
    return Promise.reject(error);
  });

// 响应拦截器
axios.interceptors.response.use(function (response) {
    // Do something with response data
    if(response.data.context&&response.data.context.jwt){
      Cookies.set('jwt',response.data.context.jwt)
    }
    return response;
  }, function (error) {
    // Do something with response error
    return Promise.reject(error);
  });

export  default axios